package com.room.search.web.rest;

import com.room.search.core.page.TableDataInfo;
import com.room.search.domain.RoomUser;
import com.room.search.response.RoomResult;
import com.room.search.service.RoomUserService;
import com.room.search.service.dto.GetBrokerDTO;
import com.room.search.service.dto.RoomUserDTO;
import com.room.search.service.dto.broker.BrokerRegisterDTO;
import com.room.search.service.dto.user.ChangeActivatedDTO;
import com.room.search.service.dto.user.RoomUserAddDTO;
import com.room.search.service.dto.user.UserRegisterDTO;
import com.room.search.web.rest.vm.UserMobileLoginVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * REST controller for managing {@link com.room.search.domain.RoomUser}.
 */
@RestController
@RequestMapping("/api/user")
public class RoomUserResource {

    private final RoomUserService roomUserService;

    public RoomUserResource(RoomUserService roomUserService) {
        this.roomUserService = roomUserService;
    }


    /**
     * ‘
     * 发烧手机短信验证码
     */
    @GetMapping("/send_sms")
    @ApiOperation("发送验证码")
    public String sendSms(@RequestParam String account) {
        return roomUserService.sendSms(account);
    }

    /**
     * 用户登录
     */
    @PostMapping("/mobile_login")
    @ApiOperation("手机快捷登录和账号密码登录")
    public RoomResult mobileLogin(@RequestBody @Valid UserMobileLoginVO vo) {
        return roomUserService.mobileLogin(vo);
    }

    /**
     * 普通用户注册
     */
    @PostMapping("/register")
    @ApiOperation("注册")
    public RoomResult userRegister(@RequestBody @Valid UserRegisterDTO dto) {
        return roomUserService.userRegister(dto);
    }

    /**
     * 经纪人注册
     */
    @PostMapping("/broker_register")
    public RoomResult brokerRegister(@RequestBody @Valid BrokerRegisterDTO dto) {
        return roomUserService.brokerRegister(dto);
    }


    /**
     * 获取用户信息
     */
    @ApiOperation("获取用户信息")
    @GetMapping("/getInfo")
    public RoomResult getUserInfo() {
        return roomUserService.getUserInfo();
    }

    /**
     * 获取所有用户列表
     */
    @ApiOperation("获取所有用户列表")
    @GetMapping("/all_user")
    public TableDataInfo getAllUsers(RoomUserDTO dto) {
        return roomUserService.getAllUsers(dto);
    }

    /**
     * 用户状态修改
     */
    @ApiOperation("用户状态修改")
    @PutMapping("/changeActivated")
    public RoomResult changeActivated(@Valid @RequestBody ChangeActivatedDTO dto) {
        return roomUserService.changeActivated(dto);
    }

    /**
     * 根据获取详细信息
     */
    @ApiOperation("根据获取详细信息")
    @GetMapping("/")
    public RoomResult addUserInfo() {
        return roomUserService.addUserInfo();
    }

    /**
     * 管理端口新增用户
     */
    @ApiOperation("新增用户")
    @PreAuthorize("@ss.hasPermi('system:user:add')")
    @PostMapping("/addUser")
    public RoomResult addUser(@RequestBody RoomUserAddDTO dto) {
        return roomUserService.addUser(dto);
    }


    /**
     * 获取经纪人
     */
    @ApiOperation("获取经纪人")
    @GetMapping("/get_broker")
    public RoomResult getBroker(GetBrokerDTO dto) {
        return roomUserService.getBroker(dto);
    }
}
